/*
 * Copyright (C) 2011 Project R'yleh Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.Arkham;

import android.os.Parcel;
import android.os.Parcelable;

public class Stats implements Parcelable {
	   private int[] stats = new int[Constants.TOTAL_STATS];
	   
	   public Stats(){
		   for(int i=0; i<Constants.TOTAL_STATS; i++)
			   stats[i]=0;
	   }
	   
	   //////////////////////////////////////////////////////////
	   /* everything below here is for implementing Parcelable */
	   //////////////////////////////////////////////////////////

	   public int describeContents() {
	       return 0;
	   }

	   // write object's data to the passed-in Parcel
	   // note that modifiers are not passed in because they are not a supported type.
	   public void writeToParcel(Parcel out, int flags) {
	       out.writeIntArray(stats);
	   }

	   // this is used to regenerate the object. 
	   // All Parcelables must have a CREATOR that implements these two methods
	   public static final Parcelable.Creator<Stats> CREATOR = new Parcelable.Creator<Stats>() {
	       public Stats createFromParcel(Parcel in) {
	           return new Stats(in);
	       }

	       public Stats[] newArray(int size) {
	           return new Stats[size];
	       }
	   };

	   // example constructor that takes a Parcel and gives you an object populated with it's values
	   private Stats(Parcel in) {
	       stats = in.createIntArray();
	   }

	   //////////////////////////////////////////////////////////
	   /* everything above here is for implementing Parcelable */
	   //////////////////////////////////////////////////////////
	   
	   public int getStrength(){
		   return stats[Constants.STRENGTH];
	   }
	   
	   public void setStrength(int newValue){
		   stats[Constants.STRENGTH] = newValue;
	   }
	   
	   public int getAgility(){
		   return stats[Constants.AGILITY];
	   }
	   
	   public void setAgility(int newValue){
		   stats[Constants.AGILITY] = newValue;
	   }
	   
	   public int getVitality(){
		   return stats[Constants.VITALITY];
	   }
	   
	   public void setVitality(int newValue){
		   stats[Constants.VITALITY] = newValue;
	   }
	   
	   public int getMagic(){
		   return stats[Constants.MAGIC];
	   }
	   
	   public void setMagic(int newValue){
		   stats[Constants.MAGIC] = newValue;
	   }
	   
	   public int getAttackPower(){
		   return stats[Constants.ATTACK_POWER];
	   }
	   
	   public void setAttackPower(int newValue){
		   stats[Constants.ATTACK_POWER] = newValue;
	   }
	   
	   public int getHitPercentage(){
		   return stats[Constants.HIT_PERC];
	   }
	   
	   public void setHitPercentage(int newValue){
		   stats[Constants.HIT_PERC] = newValue;
	   }
	   
	   public int getDefense(){
		   return stats[Constants.DEFENSE];
	   }
	   
	   public void setDefense(int newValue){
		   stats[Constants.DEFENSE] = newValue;
	   }
	   
	   public int getEvade(){
		   return stats[Constants.EVADE];
	   }
	   
	   public void setEvade(int newValue){
		   stats[Constants.EVADE] = newValue;
	   }
	   
	   public int getMagicDefense(){
		   return stats[Constants.MAGIC_DEFENSE];
	   }
	   
	   public void setMagicDefense(int newValue){
		   stats[Constants.MAGIC_DEFENSE] = newValue;
	   }
	   
	   public int getMagicEvade(){
		   return stats[Constants.MAGIC_EVADE];
	   }
	   
	   public void setMagicEvade(int newValue){
		   stats[Constants.MAGIC_EVADE] = newValue;
	   }
	   
	   public int getMaxHealth(){
		   return stats[Constants.MAX_HEALTH];
	   }
	   
	   public void setMaxHealth(int newValue){
		   stats[Constants.MAX_HEALTH] = newValue;
	   }
	   
	   public int getCurrentHealth(){
		   return stats[Constants.CURRENT_HEALTH];
	   }
	   
	   public void setCurrentHealth(int newValue){
		   stats[Constants.CURRENT_HEALTH] = newValue;
	   }
	   
	   public int getMaxMagic(){
		   return stats[Constants.MAX_MAGIC];
	   }
	   
	   public void setMaxMagic(int newValue){
		   stats[Constants.MAX_MAGIC] = newValue;
	   }
	   
	   public int getCurrentMagic(){
		   return stats[Constants.CURRENT_MAGIC];
	   }
	   
	   public void setCurrentMagic(int newValue){
		   stats[Constants.CURRENT_MAGIC] = newValue;
	   }
	   
	   public void healHealth(int healed){
		   if( (stats[Constants.MAX_HEALTH] - stats[Constants.CURRENT_HEALTH]) < healed )
			   stats[Constants.CURRENT_HEALTH] = stats[Constants.MAX_HEALTH];
		   else
			   stats[Constants.CURRENT_HEALTH] += healed;
	   }
	   
	   public void takeDamage(int damaged){
		   if( stats[Constants.CURRENT_HEALTH] < damaged )
			   stats[Constants.CURRENT_HEALTH] = 0;
		   else
			   stats[Constants.CURRENT_HEALTH] -= damaged;	   
	   }
	   
	   public void healMP(int healed){
		   if( (stats[Constants.MAX_MAGIC] - stats[Constants.CURRENT_MAGIC]) < healed )
			   stats[Constants.CURRENT_MAGIC] = stats[Constants.MAX_MAGIC];
		   else
			   stats[Constants.CURRENT_MAGIC] += healed;
	   }
	   
	   public void useMP(int used){
		   if( stats[Constants.CURRENT_MAGIC] < used )
			   stats[Constants.CURRENT_MAGIC] = 0;
		   else
			   stats[Constants.CURRENT_MAGIC] -= used;	   
	   }
	   
	   public int[] getStatsArray(){
		   return stats;
	   }
	   
	   public void setStatsArray(int[] newStats){
		   stats = newStats;
	   }
	}
